#include <stdio.h>
#include <iostream>

using namespace std;

int procuraLogo(int q[320][240], int logo[10][10], int m,int n,int x, int y)
{
	int cont =0;
	char dif = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if(i+x<=m && y+j<=n) //Dentro dos limites
			{
				for (int k = 0; k < x ; k++)
				{
					for (int l = 0; l < y ; l++)
					{
						if(logo[k][l]!=q[k+i][l+j])
							dif +=1;
						if(dif != 0) //não e o logo
							k = l = 10;						
					}
					
				}
				if(dif == 0)
					cont++;
				dif = 0;
			}//Fim dentro dos limites
			else if (i+x>=m && y+j>=n)
				i = j = 400;
			
		}
		
	}
	
	return cont;
}

int main()
{
	int x, y, k, m, n;
	int cont = 0, inst = 1;
	int pi;
	int logo[10][10];
	int quadro[320][240];
	scanf("%i %i",&x,&y);
	while(x != 0 || y != 0)
	{
		for (int i = 0; i < x; i++)
		{
			for (int j = 0; j < y; j++)
			{
				cin>>pi;
				logo[i][j] = pi;
			}			
			
		}
		scanf("%i %i %i",&k,&m,&n);
		for (int i = 0; i < k; i++)
		{
			for (int j = 0; j < m; j++)
			{
				for (int l = 0; l < n; l++)
				{
					scanf("%i",&pi);
					quadro[j][l] = pi;
				}				
			}
			cont += procuraLogo(quadro, logo, m,n,x,y);
		}	
		printf("Logotipo %i\n%i\n\n",inst,cont);
		inst ++;
		cont = 0;
		scanf("%i %i",&x,&y);
	}
	
	return 0;
}


